<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2018/5/29
 * Time: 20:00
 */

namespace app\model;


class UserMaterial extends Model
{
    public function __construct($db)
    {
        parent::__construct($db, "user_material");
    }

    /*=============================cron使用=====================*/
    public function getcronVideoMusic($limit)
    {
        $this->db->select("*");
        $this->db->from("user_material");
        $this->db->where(["mix_status!="=>1,"mix_count<"=>3]);
//        $this->db->where(["mix_status!="=>0]);
        $this->db->order_by(["mix_count"=>"asc"]);
        $this->db->limit($limit);
        $query =  $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 配音精选数据
     */
    public function index($page,$pageSize,$last_id=""){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.video_time,a.width,a.height,a.video_desc,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3]);
        $total = $this->db->count_all_results();
        $this->db->order_by(["sorts"=>"desc","add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data;
    }

    /**
     * 查询话题配音
     */
    public function type_sub_list($page,$pageSize,$type_sub){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.video_time,a.width,a.height,a.video_desc,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3,"video_join_sub"=>$type_sub]);
        $total = $this->db->count_all_results();
        $this->db->order_by(["add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data;

//        $this->db->select("video_uuid,video_big_pic,video_small_pic,transcode_video_url,video_time,height,width,first_pic1,video_desc");
//        $this->db->from("video");
//        $this->db->where(["status"=>2,"video_type"=>3,"video_join_sub"=>$type_sub]);
//        $total =  $this->db->count_all_results();
//        $this->db->order_by(["add_time"=>"desc"]);
//        $this->db->limit($pageSize,($page-1)*$pageSize);
//        $query =  $this->db->get();
//        $datas = $query->all();
//        $data["total"] = $total;
//        $data["data"] = $datas;
////        echo $this->db->last_query();exit;
//        return $data;
    }

    /**
     * 查询单个视频详情
     */
    public function dub_detail($video_uuid){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.transcode_video_no_music_url,a.transcode_no_music_zimu_video,a.cut_music_url,a.video_lines,a.video_desc,a.video_time,a.join_time,a.dub_num,a.width,a.height,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3,"video_uuid"=>$video_uuid]);
        $query =  $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 获取分类
     */
    public function dub_fenlie(){
        $this->db->select("id,name");
        $this->db->from("type");
        $this->db->where(['online'=>2,"is_other !="=>999999999,"is_xianshi"=>2]);
        $query =  $this->db->get();
        $datas = $query->all();
        return $datas;
    }

    /**
     * 查询用户上传表是否有这个分类
     */
    public function ones($table,$select,$where){
        $this->db->select($select);
        $this->db->from($table);
        $this->db->where($where);
        $this->db->limit(1,0);
        $query =  $this->db->get();
        $datas = $query->one();
        return $datas;
    }

    /**
     * 查询用户上传列表是否有这个分类下的数据
     */
    public function dub_fenlie_list($page,$pageSize,$fenlie_id){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.video_time,a.width,a.height,a.video_desc,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3,"video_join_type"=>$fenlie_id]);
        $total =  $this->db->count_all_results();
        $this->db->order_by(["add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;

    }

    /**
     * 话题下的分类点击会关联出话题
     */
    public function fenlie_guanlian_huati_type_sub($type_id,$page,$pageSize){
        $this->db->select("id,sub_title,sub_pic,sub_desc");
        $this->db->from("type_sub");
        $this->db->where(["online"=>2,"del2"=>2,"sub_type"=>$type_id]);
        $this->db->order_by(["add_times"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询这个话题在用户上传表的数据
     */
    public function fenlie_guanlian_huati_user_material($type_id,$page,$pageSize){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.duration,a.video_url,a.video_desc,a.join_type_sub,a.add_time,a.width2,a.height2,b.nick_name,a.first_pic3,b.nick_pic,c.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["a.del1"=>2,"a.examine"=>3,"a.join_type_sub"=>$type_id]);
        $total =  $this->db->count_all_results();
        $this->db->order_by(["add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
//        $this->db->limit($pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询网春大拜年的话题
     */
    public function wangchundabainian(){
        $this->db->select("id,sub_title,sub_pic,sub_desc");
        $this->db->from("type_sub");
        $this->db->where(["sub_title"=>"网春大拜年"]);
        $query =  $this->db->get();
        $datas = $query->one();
//        echo $this->db->last_query();exit;
        return $datas;
    }

    /**
     * 查询网春大拜年的话题
     */
    public function topic_wangchundabainian($page,$pageSize,$id){
        $this->db->select("a.id,a.uuid,a.video_uuid,a.pic,a.video_desc,b.nick_name,b.nick_pic,c.sub_title");
        $this->db->from("user_material as a");
        $this->db->join("users as b","a.uuid=b.uuid");
        $this->db->join("type_sub as c","a.join_type_sub=c.id");
        $this->db->where(["del1" => 2,"examine" =>3,"is_wangchun"=>3,"join_type_sub" =>$id]);
        $this->db->order_by(["id"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data["data"];



//
//        $this->db->select("id,video_uuid,pic");
//        $this->db->from("user_material");
//        $this->db->where(["del1" => 2,"examine" =>3,"is_wangchun"=>3,"join_type_sub" =>$id]);
//        $this->db->order_by(["add_time" => "desc"]);
//        $this->db->limit($pageSize,($page-1)*$pageSize);
//        $query = $this->db->get();
//        $datas = $query->all();
//        $data["data"] = $datas;
////        echo $this->db->last_query();exit;
//        return $data["data"];
    }
}